package com.kxq.zhuoyue.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kxq.zhuoyue.pageUtilEntity.Page;
import com.kxq.zhuoyue.po.*;
import com.kxq.zhuoyue.service.*;
import com.kxq.zhuoyue.util.result.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/contentReview")
public class ContentReviewController {

    @Autowired
    private ConversationService conversationService;

    @Autowired
    private AskAnswerService askAnswerService;

    @Autowired
    private ArticlesService articlesService;

    @Autowired
    private MaterialService materialService;

    @Autowired
    private BusinessCardService businessCardService;

    @Autowired
    private FormsService formsService;

    @Autowired
    private ProgramService programService;


    @PostMapping("/getByStatus")
    public AjaxResult contentReview(@RequestBody Page page){
        Map map = new HashMap<>();
        switch (page.getCategory()){
            //话术管理
            case "1":
                LambdaQueryWrapper<Conversation> queryWrapper1 = new LambdaQueryWrapper<>();
                queryWrapper1.like(Conversation::getConversationStatus,page.getStatus());
                queryWrapper1.like(Conversation::getConversationTitle,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<Conversation> list1 = conversationService.list(queryWrapper1);
                PageInfo pageInfo1 = new PageInfo<>(list1);
                map.put("data",list1);
                map.put("pageNum",pageInfo1.getPageNum());
                map.put("pageSize",pageInfo1.getPageSize());
//                return AjaxResult.success(map);
                break;
                //问答管理
            case "2":
                LambdaQueryWrapper<AskAnswer> queryWrapper2 = new LambdaQueryWrapper<>();
                queryWrapper2.like(AskAnswer::getAskAnswerStatus,page.getStatus());
                queryWrapper2.like(AskAnswer::getKeyWords,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<AskAnswer> list2 = askAnswerService.list(queryWrapper2);
                PageInfo pageInfo2 = new PageInfo<>(list2);
                map.put("data",list2);
                map.put("pageNum",pageInfo2.getPageNum());
                map.put("pageSize",pageInfo2.getPageSize());
//                return AjaxResult.success(map);
                break;
                //文章管理
            case "3":
                LambdaQueryWrapper<Articles> queryWrapper3 = new LambdaQueryWrapper<>();
                queryWrapper3.like(Articles::getArticlesStatus,page.getStatus());
                queryWrapper3.like(Articles::getArticlesTitle,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<Articles> list3 = articlesService.list(queryWrapper3);
                PageInfo pageInfo3 = new PageInfo<>(list3);
                map.put("data",list3);
                map.put("pageNum",pageInfo3.getPageNum());
                map.put("pageSize",pageInfo3.getPageSize());
//                return AjaxResult.success(map);
                break;
                //素材管理
            case "4":
                LambdaQueryWrapper<Material> queryWrapper4 = new LambdaQueryWrapper<>();
                queryWrapper4.like(Material::getMaterialStatus,page.getStatus());
                queryWrapper4.like(Material::getMaterialTitle,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<Material> list4 = materialService.list(queryWrapper4);
                PageInfo pageInfo4 = new PageInfo<>(list4);
                map.put("data",list4);
                map.put("pageNum",pageInfo4.getPageNum());
                map.put("pageSize",pageInfo4.getPageSize());
//                return AjaxResult.success(map);
                break;
            //名片管理
            case "5":
                LambdaQueryWrapper<BusinessCard> queryWrapper5 = new LambdaQueryWrapper<>();
                queryWrapper5.like(BusinessCard::getCardStatus,page.getStatus());
                queryWrapper5.like(BusinessCard::getCardName,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<BusinessCard> list5 = businessCardService.list(queryWrapper5);
                PageInfo pageInfo5 = new PageInfo<>(list5);
                map.put("data",list5);
                map.put("pageNum",pageInfo5.getPageNum());
                map.put("pageSize",pageInfo5.getPageSize());
//                return AjaxResult.success(map);
                break;
                //表单管理
            case "6":
                LambdaQueryWrapper<Forms> queryWrapper6 = new LambdaQueryWrapper<>();
                queryWrapper6.like(Forms::getFormsStatus,page.getStatus());
                queryWrapper6.like(Forms::getFormsTitle,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<Forms> list6 = formsService.list(queryWrapper6);
                PageInfo pageInfo6 = new PageInfo<>(list6);
                map.put("data",list6);
                map.put("pageNum",pageInfo6.getPageNum());
                map.put("pageSize",pageInfo6.getPageSize());
//                return AjaxResult.success(map);
                break;
            //小程序管理
            case "7":
                LambdaQueryWrapper<Program> queryWrapper7 = new LambdaQueryWrapper<>();
                queryWrapper7.like(Program::getProgramStatus,page.getStatus());
                queryWrapper7.like(Program::getProgramTitle,page.getTitle());
                PageHelper.startPage(page.getPageNum(),page.getPageSize());
                List<Program> list7 = programService.list(queryWrapper7);
                PageInfo pageInfo7 = new PageInfo<>(list7);
                map.put("data",list7);
                map.put("pageNum",pageInfo7.getPageNum());
                map.put("pageSize",pageInfo7.getPageSize());
//                return AjaxResult.success(map);
                break;
                //问卷调查
            default:

//                return AjaxResult.success();
                break;

        }
        return AjaxResult.success(map);
    }


    @PostMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody Page page){
        int up = 0;
        switch (page.getCategory()) {
            //话术管理
            case "1":
                LambdaUpdateWrapper<Conversation> updateWrapper1 = new LambdaUpdateWrapper<>();
                updateWrapper1.eq(Conversation::getConversationId, page.getDataId());
                updateWrapper1.set(Conversation::getConversationStatus, page.getStatus());
                boolean update1 = conversationService.update(updateWrapper1);
                if (update1) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //问答管理
            case "2":
                LambdaUpdateWrapper<AskAnswer> updateWrapper2 = new LambdaUpdateWrapper<>();
                updateWrapper2.eq(AskAnswer::getAskAnswerId, page.getDataId());
                updateWrapper2.set(AskAnswer::getAskAnswerStatus, page.getStatus());
                boolean update2 = askAnswerService.update(updateWrapper2);
                if (update2) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //文章管理
            case "3":
                LambdaUpdateWrapper<Articles> updateWrapper3 = new LambdaUpdateWrapper<>();
                updateWrapper3.eq(Articles::getArticlesId, page.getDataId());
                updateWrapper3.set(Articles::getArticlesStatus, page.getStatus());
                boolean update3 = articlesService.update(updateWrapper3);
                if (update3) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //素材管理
            case "4":
                LambdaUpdateWrapper<Material> updateWrapper4 = new LambdaUpdateWrapper<>();
                updateWrapper4.eq(Material::getMaterialId, page.getDataId());
                updateWrapper4.set(Material::getMaterialStatus, page.getStatus());
                boolean update4 = materialService.update(updateWrapper4);
                if (update4) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //名片管理
            case "5":
                LambdaUpdateWrapper<BusinessCard> updateWrapper5 = new LambdaUpdateWrapper<>();
                updateWrapper5.eq(BusinessCard::getBusinessCardId, page.getDataId());
                updateWrapper5.set(BusinessCard::getCardStatus, page.getStatus());
                boolean update5 = businessCardService.update(updateWrapper5);
                if (update5) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //表单管理
            case "6":
                LambdaUpdateWrapper<Forms> updateWrapper6 = new LambdaUpdateWrapper<>();
                updateWrapper6.eq(Forms::getFormsId, page.getDataId());
                updateWrapper6.set(Forms::getFormsStatus, page.getStatus());
                boolean update6 = formsService.update(updateWrapper6);
                if (update6) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //小程序管理
            case "7":
                LambdaUpdateWrapper<Program> updateWrapper7 = new LambdaUpdateWrapper<>();
                updateWrapper7.eq(Program::getProgramId, page.getDataId());
                updateWrapper7.set(Program::getProgramStatus, page.getStatus());
                boolean update7 = programService.update(updateWrapper7);
                if (update7) {
                    up = 1;
                } else {
                    up = 0;
                }
                break;
            //问卷调查
            default:

//                return AjaxResult.success();
                break;

        }
        if (up == 1){
            return AjaxResult.success("审核通过 ！");
        }else {
            return AjaxResult.success("审核未通过 ！");
        }
    }

}
